//  Copyright 2008 Stefan Kristiansson
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the Lesser GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  Lesser GNU General Public License for more details.
//
//  You should have received a copy of the Lesser GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.

// WrapperExample.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <math.h>
#include <string.h>
#ifndef M_PI 
#define M_PI 3.1415926535897932384626433832795 
#endif
#include "..\\..\\..\\CemeWrapper\\CemeWrapper.h"
double funcCircle(double *args)
{
	return M_PI * pow(args[0],2);
}
int _tmain(int argc, _TCHAR* argv[])
{
	char expression[256];
	CemeInit();
	//Add a custom function that calculates the area of a circle from the radius
	CemeAddFunction("circle",1,&funcCircle);
	while(1)
	{
		printf(">");
		gets_s(expression,256);
		CemeSetExpression(expression);
		if (!strcmp(expression,"quit") || !strcmp(expression,"exit"))
			return 0;
		int cnt = CemeGetVariableCount();
		for(int i=0;i<cnt;i++)
		{
			char *var = CemeGetVariable(i);
			CemeSetVariable(var,i+1);
		}
		double result = CemeEvaluate();
		printf("   = %f\n",result);
	}
	return 0;
}

